import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syria_sports/data/controllers/additional_operations_controller.dart';
import 'package:syria_sports/data/models/data.dart';

import '../../../data/apiClient/api_client.dart';

part 'other_tab_state.dart';

class AdditionalOperationsCubit extends Cubit<AdditionalOperationsState> {
  AdditionalOperationsCubit() : super(AdditionalOperationsInitial());

  static AdditionalOperationsCubit get(context) => BlocProvider.of(context);

  late String? route;

  Map<String , dynamic> uiData = {
  "type": "Container",
  "color": "#FF00FF"
  };

  late Data data;


  void init({String? route}) {
    this.route =route;
    getUI();
  }

  getUI()async{
    //return;
    emit(AdditionalOperationsLoading());
    await AdditionalOperationsController.getUIAndDataFrom(route??ApiClient.other).then((value) {
      if(value != null) {
        data = value;
        if(data.ui != null) {
          uiData = data.ui!;
        }
        emit(AdditionalOperationsDone());
      }else{
        emit(AdditionalOperationsError());
      }
    });
  }

  update(){
    emit(AdditionalOperationsUpdate());
  }
}
